/*
 * BitStreamTest.cpp
 *
 *  Created on: 28 de Mai de 2011
 *      Author: ei10139
 */

#include "BitStreamTest.h"

void BitStreamTest::constructor()
{
	BitStreamTest bst;
	ASSERT_EQUAL(0, bst.offsetRead);
	ASSERT_EQUAL(0, bst.offsetWrite);
}

void BitStreamTest::writeTestBool()
{
	BitStreamTest bst;
	bst.write(true);
	bst.write(false);
	ASSERT_EQUAL(true, bst.bits[0]);
	ASSERT_EQUAL(false, bst.bits[1]);
}

void BitStreamTest::writeTestBit()
{
	BitStreamTest bst;
	bst.write(true);
	bst.write(false);
	ASSERT_EQUAL(1, bst.bits[0]);
	ASSERT_EQUAL(0, bst.bits[1]);
}

void BitStreamTest::writeTestBitStream()
{
	BitStreamTest bst;
	bst.write(true);
	bst.write(false);
	BitStreamTest bst2;
	bst2.write(&bst);
	bst2.write(&bst);
	ASSERT_EQUAL(1, bst2.bits[0]);
	ASSERT_EQUAL(0, bst2.bits[1]);
	ASSERT_EQUAL(1, bst2.bits[2]);
	ASSERT_EQUAL(0, bst2.bits[3]);
	for(unsigned int i = 0; i < 32 * 256; ++i)
		bst.write(true, true);
	for(unsigned int i = 0; i < 128 * 256 * 256; ++i) // 1mg of bits
		bst.write(true);
	for(unsigned int i = 0; i < 16; ++i)
		bst.write(false, true);
}

void BitStreamTest::sizeTest()
{
	BitStreamTest bst;
	ASSERT_EQUAL(0, bst.size());
	bst.write(true);
	bst.write(false);
	ASSERT_EQUAL(2, bst.size());
	bst.write(false);
	ASSERT_EQUAL(3, bst.size());
}

void BitStreamTest::getTest()
{
	bool bit0 = false;
	bool bit1 = true;
	BitStreamTest bst;
	bst.write(bit0);
	bst.write(bit1);
	ASSERT_EQUAL(bit0, bst.get());
	ASSERT_EQUAL(bit1, bst.get());
	ASSERT(NULL == bst.get());
}

void BitStreamTest::eosTest()
{
	BitStreamTest bst;
	ASSERT(bst.eos());
	bst.write(true);
	bst.write(true);
	ASSERT(!bst.eos());
	bst.get();
	ASSERT(!bst.eos());
	bst.get();
	ASSERT(bst.eos());
}

void BitStreamTest::runSuite()
{
	cute::suite s;
	s.push_back(CUTE(BitStreamTest::constructor));
	s.push_back(CUTE(BitStreamTest::writeTestBool));
	s.push_back(CUTE(BitStreamTest::writeTestBit));
	s.push_back(CUTE(BitStreamTest::writeTestBitStream));
	s.push_back(CUTE(BitStreamTest::sizeTest));
	s.push_back(CUTE(BitStreamTest::getTest));
	s.push_back(CUTE(BitStreamTest::eosTest));
	cute::ide_listener lis;
	cute::makeRunner(lis)(s, "The BitStreamTest Suite");
}
